//
//  MeVC.m
//  Ginix
//
//  Created by 冯志强 on 2025/2/14.
//

#import "MeVC.h"
#import "MeHearView.h"
#import "MeListCell.h"

@interface MeVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UIImageView * iconView;
@property (nonatomic,strong) MeHearView * headView;
@property (nonatomic,strong) UITableView * listView;
@end

@implementation MeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatMoreBtn];
    [self setSubViewLayout];
}

-(void)creatMoreBtn{
    
    
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self requestData];

}

-(void)requestData{
    
    @WeakObj(self)
    [SPNetworkingIns GET:PORT(@"user-center/api/appUser/getAppUserInfo") params:@{} success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject, NSInteger code) {
       @StrongObj(self)
       UserInfoModel * model = [UserInfoModel yy_modelWithDictionary:responseObject[@"data"]];
       [UserInfoModel shareInstance].userModel = model;
       [self.headView setInfoModel:model];
       
    } fail:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        
    }];
    
}

-(void)setSubViewLayout{
    
    [self.view addSubview:self.iconView];
    [self.view addSubview:self.listView];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 470 * FMScaleX;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    MeListCell * cell = [tableView dequeueReusableCellWithIdentifier:@"MeListCell"];
    return cell;
}

-(UIImageView *)iconView{
    
    if (!_iconView) {
        _iconView = [[UIImageView alloc]initWithFrame:CGRectMake(0, StatusBar, WIDTH, 180 * FMScaleX)];
        _iconView.image = [UIImage imageNamed:@"Me_head_bg"];
    }
    return _iconView;
}

-(UITableView *)listView{
    
    if (!_listView) {
        _listView = [[UITableView alloc]initWithFrame:CGRectMake(0, NavHeight, WIDTH, HEIGHT - NavHeight - kSafeAreaHeight  - 60 * FMScaleX - TabBarHeight)];
        _listView.delegate = self;
        _listView.dataSource = self;
        _listView.showsVerticalScrollIndicator = NO;
        _listView.showsHorizontalScrollIndicator = NO;
        _listView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _listView.backgroundColor = UIColor.clearColor;
        [_listView registerClass:[MeListCell class] forCellReuseIdentifier:@"MeListCell"];
        _listView.tableHeaderView = self.headView;
    }
    return _listView;
}
-(MeHearView *)headView{
    
    if (!_headView) {
        _headView = [[MeHearView alloc]initWithFrame:CGRectMake(0, NavHeight, WIDTH, 120 * FMScaleX)];
    }
    return _headView;
}
@end
